﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Bll;
using AspNetCs.Model;
using AspNetCs.Common;
using AspNetCs.Config;
using System.Data;
using System.Data.SqlClient;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.Channel_Enum;

public partial class Master_Admin_ManageJuanKuan : Admin_BasePage
{
    protected City city = new City();
    Alms_BLL bll = AlmsBll.CreateNew;

    protected void Page_Load(object sender, EventArgs e)
    {
        IsExit();
        if (!IsPostBack)
        {
            dataBind();
        }

    }

    public string GetChannel_Enum(string str)
    {
        int channelId = StringHelper.isNumber_int(str);
        Channel_Type channelType = (Channel_Type)channelId;
        return EnumDescription.GetFieldText(channelType);

    }

    public string GetAmsType(string str)
    {
        string amsType="";
        switch(str)
        {   
            case "1":
                amsType = "直接扣点";
                break;
            case "2":
                amsType = "银行支付";
                break;
            default:
                break;

        }
        return amsType;

    }

    protected void dataBind()
    {
        string cmdText = "select *,CreateName=(select UserName from Users where Userid=al.UserId) from Alms as al order by ID desc";
        AspNetCs.Common.DataPagesOperate operate = new DataPagesOperate();

        operate.BindRepeater(cmdText, AspNetPager1, "ID desc", "ID", rptNetMuList);


    }


    protected void rptNetMuList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        LinkButton lbtn = null;
        try
        {
            int count = 0;
            string id = "";
            int NetMuId = 0;
            if (e.CommandName == "delete")
            {
                lbtn = e.Item.FindControl("btn_del") as LinkButton;
                id = lbtn.CommandArgument;
                NetMuId = Convert.ToInt32(id);
                bool bo = false;

                count = bll.Delete("ID=" + NetMuId);
                bo = count > 0 ? true : false;
                if (bo)
                {
                    showMessage("deleteSucce", "删除成功");
                    dataBind();
                }
                else
                {
                    showMessage("deleteFaith", "删除失败");
                    dataBind();
                }
            }
            else if (e.CommandName == "pay")
            { 
                lbtn = e.Item.FindControl("lbtnPay") as LinkButton;
                int isPay = 0;
                if (lbtn.Text == "审核")
                {
                    isPay = 1;
                }
                else if (lbtn.Text == "取消审核")
                {
                    isPay = 0;
                }
                id = lbtn.CommandArgument;
                NetMuId = Convert.ToInt32(id);
                bool bo = false;

                count = bll.setPay(isPay,"ID=" + NetMuId);
                dataBind();
            }
           
        }
        catch (Exception ex)
        {
            new CustomException(ex);
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        dataBind();
    }
    protected void rptNetMuList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if(e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.Item)
        {
            HiddenField hldAmsType = e.Item.FindControl("hldAmsType") as HiddenField;
            HiddenField hldPayType = e.Item.FindControl("hldPayType") as HiddenField;
            LinkButton lbtn = e.Item.FindControl("lbtnPay") as LinkButton;
            int isPay = 0;
            string amsType = hldAmsType.Value;
            switch(amsType)
            {
                case "1":
                    lbtn.Visible = false;
                    break;
                case "2":
                    lbtn.Visible = true;
                    break;
            }
            if (hldPayType.Value == "0")
            {
                lbtn.Text = "审核";
            }
            else if (hldPayType.Value == "1")
            {
                lbtn.Text = "取消审核";
            }
        }
        
    }
}
